<html>
<head><meta charset="utf-8"><title>uniform-paths · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html">uniform-paths</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="131219497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131219497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131219497">(Aug 10 2018 at 06:30)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> hi! should've contacted you here sooner. anyway, I'm still trying to fix the fallout from some of my changes and I keep finding bugs :(</p>



<a name="131219552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131219552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131219552">(Aug 10 2018 at 06:31)</a>:</h4>
<p>so what I noticed is the <code>use $crate;</code> warning doesn't fire for <code>use $crate::{self};</code> <a href="http://play.rust-lang.org/?gist=b4cf86e1f8bf5b2007165912f38afc57&amp;version=stable&amp;mode=debug&amp;edition=2015" target="_blank" title="http://play.rust-lang.org/?gist=b4cf86e1f8bf5b2007165912f38afc57&amp;version=stable&amp;mode=debug&amp;edition=2015">http://play.rust-lang.org/?gist=b4cf86e1f8bf5b2007165912f38afc57&amp;version=stable&amp;mode=debug&amp;edition=2015</a></p>



<a name="131219593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131219593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131219593">(Aug 10 2018 at 06:32)</a>:</h4>
<p>I'm assuming I can just move that around so it always fires if the final path is just one <code>$crate</code> segment</p>



<a name="131219603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131219603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131219603">(Aug 10 2018 at 06:33)</a>:</h4>
<p>also, <code>use $crate;</code> was converted into <code>use crate_name as crate_name;</code> <em>not</em> <code>use $crate as crate_name;</code> which meant things could go wrong if the <code>extern crate</code> the macro came from was renamed :/ (also, it doesn't work same-crate <em>at all</em>)</p>



<a name="131219676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131219676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131219676">(Aug 10 2018 at 06:35)</a>:</h4>
<p>I made it a bit more uniform so now it can resolve same-crate (but if you don't rename the import you can't access it because it picks up the crate name from the root module and that's empty for the current crate). <code>use $crate as foo;</code> seems... reasonable IMO, it's only <code>use $crate;</code> that's bad because of the rename to <code>$crate</code></p>



<a name="131219784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131219784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131219784">(Aug 10 2018 at 06:38)</a>:</h4>
<p>so one weird thing is I broke <code>import-crate-var</code>, it gives me:</p>
<div class="codehilite"><pre><span></span>error[E0425]: cannot find function `f` in module `import_crate_var`
  --&gt; /home/eddy/Projects/rust-2/src/test/compile-fail/import-crate-var.rs:22:5
   |
LL |     m!();
   |     ^^^^^ not found in `import_crate_var`
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: possible candidate is found in another module, you can import it into scope
   |
LL | use import_crate_var::f;
   |
</pre></div>



<a name="131219806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131219806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131219806">(Aug 10 2018 at 06:39)</a>:</h4>
<p>so what sort of weird module with <code>f</code> missing, is that? ohhhhhh it's not hitting the cross-crate code path, which means it's not getting populated, hah! (I'm rubber ducking now, I guess)</p>



<a name="131221048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131221048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131221048">(Aug 10 2018 at 07:13)</a>:</h4>
<p>hmm <code>populate_module_if_necessary</code> is not enough to be able to access items from the "module"</p>



<a name="131221622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131221622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131221622">(Aug 10 2018 at 07:26)</a>:</h4>
<p>ugh <code>use $crate;</code> probably only worked because it was basically <code>use "" as "";</code> which is cyclical</p>



<a name="131224666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131224666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131224666">(Aug 10 2018 at 08:37)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> I'm not sure how often <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> comes online here; internals is maybe best?</p>



<a name="131227756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131227756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131227756">(Aug 10 2018 at 09:46)</a>:</h4>
<blockquote>
<p>I'm not sure how often @Vadim Petrochenkov comes online here</p>
</blockquote>
<p>Twice a day, in the morning and in the evening (GMT+3), same for internals.</p>



<a name="131228155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131228155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131228155">(Aug 10 2018 at 09:56)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> <br>
Yes, single segment imports were already buggy for all special segment (self, super, $crate, now crate) - e.g. <a href="https://github.com/rust-lang/rust/issues/37156" target="_blank" title="https://github.com/rust-lang/rust/issues/37156">https://github.com/rust-lang/rust/issues/37156</a>, <a href="https://github.com/rust-lang/rust/issues/35612" target="_blank" title="https://github.com/rust-lang/rust/issues/35612">https://github.com/rust-lang/rust/issues/35612</a>.<br>
I wanted to fix it this summer, but other stuff was higher priority.</p>
<p><code>use $crate;</code> was a warning long enough, I think it can be made an error now if necessary.<br>
The intended (at least by me, but it was also discussed in one of the module rfc threads with the same conclusion), but not yet implemented rule is that every import must have a name</p>
<div class="codehilite"><pre><span></span><span class="k">use</span><span class="w"> </span><span class="k">crate</span><span class="p">;</span><span class="w"> </span><span class="c1">// BAD, same for $crate</span>
<span class="k">use</span><span class="w"> </span><span class="k">crate</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">name</span><span class="p">;</span><span class="w"> </span><span class="c1">// GOOD, same for $crate</span>
<span class="k">use</span><span class="w"> </span><span class="k">super</span><span class="p">;</span><span class="w"> </span><span class="c1">// BAD</span>
<span class="k">use</span><span class="w"> </span><span class="k">super</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">name</span><span class="p">;</span><span class="w"> </span><span class="c1">// GOOD</span>
<span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="p">{</span><span class="bp">self</span><span class="p">};</span><span class="w"> </span><span class="c1">// BAD</span>
<span class="k">use</span><span class="w"> </span><span class="n">name</span>::<span class="p">{</span><span class="bp">self</span><span class="p">};</span><span class="w"> </span><span class="c1">// GOOD, name can come from a previous segment for `self`</span>
<span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="p">{</span><span class="bp">self</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">name</span><span class="p">};</span><span class="w"> </span><span class="c1">// Also GOOD</span>
</pre></div>


<p>and that implicit naming like <code>use $crate</code> -&gt; <code>use crate_name</code> should never be done.</p>



<a name="131228404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131228404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131228404">(Aug 10 2018 at 10:03)</a>:</h4>
<p>I agree, although I think for now I'll try to do the simplest thing that works, since this is taking way too long</p>



<a name="131230494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131230494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131230494">(Aug 10 2018 at 10:57)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> do you have an opinion on <a href="https://github.com/rust-lang/rust/issues/53128#issuecomment-411991950" target="_blank" title="https://github.com/rust-lang/rust/issues/53128#issuecomment-411991950">https://github.com/rust-lang/rust/issues/53128#issuecomment-411991950</a>? I have the "force <code>extern_prelude</code> on everyone" in my PR but I think I need to take it out to avoid having to rewrite all the tests, and I think I'll go with the second thing (i.e. <code>test::foo</code> doesn't imply <code>::test::foo</code> unless <code>test</code> is in <code>extern_prelude</code>, for both ambiguity checking and actual resolution)</p>



<a name="131230634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131230634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131230634">(Aug 10 2018 at 11:00)</a>:</h4>
<p>I finally figured out how <code>edition-lint-paths</code> is supposed to work, heh, so you turn on <em>some</em> features from the new edition, <em>without</em> switching to it (so <code>#![feature(rust_2018_preview)]</code>is only a subset of <code>--edition 2018</code>'s effects), and then you get a bunch of lints</p>



<a name="131231221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231221">(Aug 10 2018 at 11:16)</a>:</h4>
<blockquote>
<p>Alternatively, we can make ::crate_name not work for any crate not in the extern_prelude, and still require extern crate</p>
</blockquote>
<p>I think we can do that, at least initially.<br>
This mostly affects proc_macros and private rustc crates, so this should be rare and shouldn't affect new users.</p>



<a name="131231254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231254">(Aug 10 2018 at 11:18)</a>:</h4>
<p>also bench stuff I guess</p>



<a name="131231285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231285">(Aug 10 2018 at 11:18)</a>:</h4>
<p>we can land it but maybe we should do it separately from the main PR, whereas everything else is needed for <code>#![feature(uniform_paths)]</code> to even <em>work at all</em></p>



<a name="131231305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231305">(Aug 10 2018 at 11:19)</a>:</h4>
<p>In the "true uniform path" model imports are resolved as any non-imports, so local modules shadow extern crates and <code>::test</code> vs <code>self::test</code> is not an error.<br>
When it's implemented we can allow <code>::my_crate</code> to refer to non-prelude crates again.</p>



<a name="131231354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231354">(Aug 10 2018 at 11:20)</a>:</h4>
<p>FWIW I... have that implemented</p>



<a name="131231374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231374">(Aug 10 2018 at 11:21)</a>:</h4>
<p>or, well, with one tiny caveat, single-segment imports have the preference order flipped</p>



<a name="131231382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231382">(Aug 10 2018 at 11:22)</a>:</h4>
<p>(Also, I should go right now, will answer later.)</p>



<a name="131231421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131231421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131231421">(Aug 10 2018 at 11:22)</a>:</h4>
<p>but the main part of the resolution involves treating import paths as relative paths</p>



<a name="131233117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131233117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131233117">(Aug 10 2018 at 12:02)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> so uhhh I think I actually implemented "try in self and only if it's not in there try an external crate". I'll put it in a separate commit from the ambiguity canary thing</p>



<a name="131236409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131236409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131236409">(Aug 10 2018 at 13:13)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> while I'm waiting for another build, I came up with this:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">mod</span> <span class="nn">test</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Foo</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="n">test</span>::<span class="n">Foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="n">test</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">foo</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>I don't know yet if <code>#![feature(uniform_paths)]</code> allows it (assuming the ambiguity canary doesn't trip, e.g. due to <code>--extern test=...</code> - cause that has explicit <code>self</code> which shouldn't allow reaching the inner module) but <em>it might</em>, and I think I know how to solve it:</p>
<p>Add another argument to <code>resolve_path</code> for the initial value of <code>module</code>, and pass <code>Some(UniformRoot)</code> for imports, <em>in all editions</em>.<br>
This will ensure that single-segment imports don't go through a different codepath than the first segment of a multi-segment import.</p>



<a name="131239363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131239363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131239363">(Aug 10 2018 at 14:09)</a>:</h4>
<p>hmm <code>resolve_ident_in_lexical_scope</code> is a pretty bad thing to hit because it resolves absolutely if there are no ribs</p>



<a name="131836462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131836462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131836462">(Aug 10 2018 at 17:31)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span>  see the edit here: <a href="https://github.com/rust-lang/rust/pull/52923#issuecomment-412120808" target="_blank" title="https://github.com/rust-lang/rust/pull/52923#issuecomment-412120808">https://github.com/rust-lang/rust/pull/52923#issuecomment-412120808</a> - basically, since (I think) I'm much closer to your intended "uniform approach", we can probably get rid of the hacky ambiguity detection and instead <em>just check</em> if both things we wanted to resolve to, exist, while resolving them</p>
<p>maybe the <code>UniformRoot(keywords::Invalid.name())</code> hack is too much of a hack and we should have two variants (or <code>Option</code> around the name), one for the "absolute mode" (<code>use ::x::...;</code>) and one for the "maybe-relative mode" (<code>use x::...;</code>), but other than that...</p>



<a name="131929275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131929275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131929275">(Aug 11 2018 at 00:17)</a>:</h4>
<blockquote>
<p>I'm much closer to your intended "uniform approach", we can probably get rid of the hacky ambiguity detection and instead just check if both things we wanted to resolve to, exist, while resolving them</p>
</blockquote>
<p>The key issue with import (and macro) paths is that "whether they exist" is not a well-formed question.<br>
It may be nonexistent at one moment of time when we check it, but then start to exist at later moment of time.<br>
That's why <code>resolve_lexical_macro_path_segment</code> has to track all these "potentially ambiguous results" and work in two passes - one for initial resolution and another for validation (in <code>fn finalize_current_module_macro_resolutions</code>).</p>
<p>The <code>self.resolve_ident_in_module_unadjusted(...).is_ok()</code> in <a href="https://github.com/rust-lang/rust/pull/52923/commits/5e24cb92245ae7f124a55f5413c2e8b4ba25c12c" target="_blank" title="https://github.com/rust-lang/rust/pull/52923/commits/5e24cb92245ae7f124a55f5413c2e8b4ba25c12c">https://github.com/rust-lang/rust/pull/52923/commits/5e24cb92245ae7f124a55f5413c2e8b4ba25c12c</a> falls exactly into this trap - is_ok can return false at one moment of time, but the local module can be defined <em>after</em> that.</p>



<a name="131929450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131929450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131929450">(Aug 11 2018 at 00:23)</a>:</h4>
<p>The scheme with <code>use</code> cloning was supposed to avoid dealing with this more tricky stuff to get the result quicker, even if it's more conservative than strictly necessary.</p>



<a name="131929526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131929526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131929526">(Aug 11 2018 at 00:25)</a>:</h4>
<p>I think the conclusion from this is that the canaries are still useful to conservatively error in all weird cases when <code>resolve_ident_in_module_unadjusted</code> returns false negative.</p>



<a name="131938521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131938521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131938521">(Aug 11 2018 at 05:00)</a>:</h4>
<p>Okay, thanks, that means I'll keep the current version of the canaries and note the fact that they're needed <em>because</em> the implementation isn't sophisticated enough to <em>always</em> pick <code>self::x</code> over <code>::x</code> if the former <em>eventually</em> exists, wrt macro expansion</p>



<a name="131941308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131941308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131941308">(Aug 11 2018 at 06:23)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> heh, funnily enough this works as expected:</p>
<div class="codehilite"><pre><span></span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">mod</span> <span class="nn">std</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Foo</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="p">{</span><span class="n">Foo</span><span class="p">,</span><span class="w"> </span><span class="n">Bar</span><span class="p">};</span><span class="w"></span>
<span class="n">m</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
</pre></div>


<p>(even though there's the ambiguity error, only <code>Bar</code> <em>also</em> gets a resolution failure, <code>Foo</code> succeeds)<br>
So I'm guessing a problematic testcase would be more involved?</p>



<a name="131944699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131944699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131944699">(Aug 11 2018 at 08:16)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> Hmm I think I came up with a simpler ambiguity canary scheme: since we rely on <code>extern_prelude</code> for checking if we're supposed to resolve to <code>::x</code>, <em>ever</em>, we can have only one canary import, for <code>self::x</code>, and in <code>finalize_imports</code>, ignore errors for these canaries and treat their success as ambiguity errors, instead of relying on a pair of them coexisting</p>



<a name="131944755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131944755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131944755">(Aug 11 2018 at 08:18)</a>:</h4>
<p>Furthermore, if we do it this way, it should be possible to have one canary for each of the non-module scopes ("non-normal modules" in <code>rustc_resolve</code> terminology) around the , to <em>also</em> error in a case like this:</p>
<div class="codehilite"><pre><span></span><span class="k">enum</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">enum</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="cm">/*self::*/</span><span class="n">Foo</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="131944761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/131944761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#131944761">(Aug 11 2018 at 08:19)</a>:</h4>
<p>As one might expect that not writing <code>self</code> there, with <code>#![feature(uniform_paths)]</code>, would resolve to the inner <code>Foo</code>, but <code>self</code> always resolves in the "normal module"</p>



<a name="132097989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132097989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132097989">(Aug 14 2018 at 08:44)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> woo, it landed! and it broke clippy &amp; rls, sadly. r? <a href="https://github.com/rust-lang/rust/pull/53335" target="_blank" title="https://github.com/rust-lang/rust/pull/53335">https://github.com/rust-lang/rust/pull/53335</a></p>



<a name="132200550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132200550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Huber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132200550">(Aug 15 2018 at 21:23)</a>:</h4>
<p>Should bugs be filed for things like uniform-paths? I'm <em>fairly</em> sure this is a bug. At the very least It's confusing to me.  Enabling uniform_paths, there's a detected ambiguous <code>use</code> for <code>log</code>. But I can't figure out <em>where</em> the non-crate <code>log</code> is coming from. Furthermore, if I change <code>use log;</code> to <code>use self::log;</code>, just to see if it'll work, the compiler claims there's no <code>log</code> module in the root. Weird, maybe?</p>
<p><a href="https://play.rust-lang.org/?gist=f749f38540242c143f2e4c41e2f1625c&amp;version=nightly&amp;mode=debug&amp;edition=2018" target="_blank" title="https://play.rust-lang.org/?gist=f749f38540242c143f2e4c41e2f1625c&amp;version=nightly&amp;mode=debug&amp;edition=2018">https://play.rust-lang.org/?gist=f749f38540242c143f2e4c41e2f1625c&amp;version=nightly&amp;mode=debug&amp;edition=2018</a></p>
<div class="codehilite"><pre><span></span>error: import from `log` is ambiguous
 --&gt; src/main.rs:3:5
  |
3 | use log;
  |     ^^^
  |     |
  |     could refer to external crate `::log`
  |     could also refer to `self::log`
  |
  = help: write `::log` or `self::log` explicitly instead
  = note: relative `use` paths enabled by `#![feature(uniform_paths)]`
</pre></div>



<a name="132200620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132200620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Huber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132200620">(Aug 15 2018 at 21:24)</a>:</h4>
<p>after changing to <code>use self::log;</code>:</p>
<div class="codehilite"><pre><span></span>error[E0432]: unresolved import `self::log`
 --&gt; src/main.rs:3:5
  |
3 | use self::log;
  |     ^^^^^^^^^ no `log` in the root
</pre></div>


<p>:)</p>



<a name="132201893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132201893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132201893">(Aug 15 2018 at 21:53)</a>:</h4>
<p><span class="user-mention" data-user-id="120512">@wootsuit</span> Yes, if there's problems or inconsistencies please do file bugs</p>



<a name="132202117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132202117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Huber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132202117">(Aug 15 2018 at 21:58)</a>:</h4>
<p>Ok, I will! Thanks!</p>



<a name="132204304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132204304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Huber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132204304">(Aug 15 2018 at 22:40)</a>:</h4>
<p>Ok, makes sense now (thanks @eddyb :), and still surprising to me! Turns out, it's that the <code>log</code> crate has a <code>log</code> name exported, so it's the act of using  <code>log</code>, or even <code>log::log</code> that's creating the ambiguity!  <a href="https://github.com/rust-lang/rust/issues/53408" target="_blank" title="https://github.com/rust-lang/rust/issues/53408">https://github.com/rust-lang/rust/issues/53408</a></p>



<a name="132207139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132207139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132207139">(Aug 15 2018 at 23:46)</a>:</h4>
<p>oh sorry I didn't see this here (you need to write @eddyb <em>and</em> press enter to let it complete to <span class="user-mention" data-user-id="119009">@eddyb</span> - only the latter notifies me)</p>



<a name="132207155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132207155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132207155">(Aug 15 2018 at 23:47)</a>:</h4>
<p><span class="user-mention" data-user-id="120512">@uberjay</span> ^^</p>



<a name="132209882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132209882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Huber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132209882">(Aug 16 2018 at 00:59)</a>:</h4>
<p>Ah, I didn’t realize! Thanks, again!</p>



<a name="132239408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132239408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132239408">(Aug 16 2018 at 13:23)</a>:</h4>
<p><span class="user-mention" data-user-id="120512">@uberjay</span> fix is up! <a href="https://github.com/rust-lang/rust/pull/53427" target="_blank" title="https://github.com/rust-lang/rust/pull/53427">https://github.com/rust-lang/rust/pull/53427</a></p>



<a name="132248855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132248855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Huber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132248855">(Aug 16 2018 at 16:01)</a>:</h4>
<p>So fast! I just tried it out (yes I am recreationally building the compiler :), and it seems to work well! <span class="emoji emoji-1f389" title="tada">:tada:</span></p>



<a name="132344814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132344814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132344814">(Aug 18 2018 at 05:20)</a>:</h4>
<p>Update: nightly now includes these Rust 2018 changes:</p>
<ul>
<li><a href="https://github.com/rust-lang/rust/pull/53427" target="_blank" title="https://github.com/rust-lang/rust/pull/53427">#53427 rustc_resolve: overhaul <code>#![feature(uniform_paths)]</code> error reporting.</a></li>
<li><a href="https://github.com/rust-lang/rust/pull/53347" target="_blank" title="https://github.com/rust-lang/rust/pull/53347">#53347 rustc_resolve: don't allow paths starting with <code>::crate</code>.</a></li>
<li><a href="https://github.com/rust-lang/rust/pull/53413" target="_blank" title="https://github.com/rust-lang/rust/pull/53413">#53413 Warn that <code>#![feature(rust_2018_preview)]</code> is implied when the edition is set to Rust 2018.</a></li>
</ul>



<a name="132344825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132344825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132344825">(Aug 18 2018 at 05:20)</a>:</h4>
<p><span class="user-mention" data-user-id="120512">@uberjay</span> so you should be able to use nightly :D</p>



<a name="132408233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132408233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132408233">(Aug 19 2018 at 14:42)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> ugh, I just realized <code>pub use crate_name;</code> doesn't work with uniform_paths and that seems a bit bad</p>



<a name="132530272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132530272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132530272">(Aug 21 2018 at 17:30)</a>:</h4>
<p>yeah, that is what I was worried about</p>



<a name="132544565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132544565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132544565">(Aug 21 2018 at 22:08)</a>:</h4>
<p>Part of me wants to say that you shouldn't be doing that anyway because it's better to depend directly, in most cases.</p>
<p>This should work though, right? So there is <em>a</em> replacement:</p>
<div class="codehilite"><pre><span></span><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">crate_name</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span>::<span class="n">crate_name</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="132545844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545844">(Aug 21 2018 at 22:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> <code>pub use ::crate_name</code> also works</p>



<a name="132545849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545849">(Aug 21 2018 at 22:42)</a>:</h4>
<p>it's just awkward</p>



<a name="132545852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545852">(Aug 21 2018 at 22:42)</a>:</h4>
<p>not.. too bad, though; I'd sort of presume that sort of thing is fairly rare</p>



<a name="132545854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545854">(Aug 21 2018 at 22:42)</a>:</h4>
<p>I wonder how difficult it would be to get statistics</p>



<a name="132545857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545857">(Aug 21 2018 at 22:42)</a>:</h4>
<p>presumably</p>



<a name="132545861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545861">(Aug 21 2018 at 22:42)</a>:</h4>
<p>it's a bit annoying because it's a "false ambiguity", in a way</p>



<a name="132545869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545869">(Aug 21 2018 at 22:43)</a>:</h4>
<p>sure, yeah -- the problem is that crate_name is already imported, right?</p>



<a name="132545870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545870">(Aug 21 2018 at 22:43)</a>:</h4>
<p>In theory we could ignore that for crates? We'd need to special-case it I guess</p>



<a name="132545920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545920">(Aug 21 2018 at 22:44)</a>:</h4>
<p>I haven't really thought that deeply about it, tbh</p>



<a name="132545922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545922">(Aug 21 2018 at 22:44)</a>:</h4>
<p>feels like we should model it with prolog and let a slg solver loose on it :P</p>



<a name="132545924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132545924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132545924">(Aug 21 2018 at 22:44)</a>:</h4>
<p>/me only half joking</p>



<a name="132549348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132549348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132549348">(Aug 22 2018 at 00:05)</a>:</h4>
<blockquote>
<p>the problem is that crate_name is already imported, right?</p>
</blockquote>
<p>That's implementation details leaking, not a fundamental restriction.</p>



<a name="132550621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132550621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132550621">(Aug 22 2018 at 00:39)</a>:</h4>
<p>In theory I think the std prelude today is <code>use std::prelude::*</code> so I wonder if we can't do the same treatment here (redefining prelude imports is fine)</p>



<a name="132553547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132553547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132553547">(Aug 22 2018 at 02:00)</a>:</h4>
<p>Yeah this is fine, it's just the ambiguity canary that's externally visible.</p>



<a name="132553688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132553688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132553688">(Aug 22 2018 at 02:05)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> Do you think we should "just" detect the case where the <code>use self::x;</code> canary detected the import itself, and omit the canary error? That would allow <code>use crate_name;</code> but not <code>use crate_name::{self};</code> (because of different ID)</p>



<a name="132553731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132553731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132553731">(Aug 22 2018 at 02:06)</a>:</h4>
<p>we can warn that it's unnecessary or whatever, if private, but at least it wouldn't  error</p>



<a name="132553997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132553997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132553997">(Aug 22 2018 at 02:17)</a>:</h4>
<blockquote>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> Do you think we should "just" detect the case where the <code>use self::x;</code> canary detected the import itself, and omit the canary error? That would allow <code>use crate_name;</code> but not <code>use crate_name::{self};</code> (because of different ID)</p>
</blockquote>
<p>I think we can do that in short term.</p>



<a name="132554043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132554043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132554043">(Aug 22 2018 at 02:18)</a>:</h4>
<p>I kept trying to come up with nice ways of catching the relevant cases but allowing them seems easier than having any sort of coherent error (and the errors don't make sense if there's a re-export - for whatever reason)</p>



<a name="132621648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132621648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132621648">(Aug 23 2018 at 06:53)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> what if we inject the canaries on Rust2015 with <code>#![feature(uniform_paths)]</code> and warn about writing <code>use ::crate_name</code> when they'd get an ambiguity error after they switch version? they don't create name conflicts anymore, and have their own error reporting, so on non-Rust2018 we can just emit a lint instead, <em>including</em> automatically applicable diagnostics, I <em>think</em> (in the case where you wrote <code>use name::...</code> and not <code>use {name:::</code> - wait, hang on, <code>use {::std::io}</code> works with uniform_paths lol, that's nice)</p>



<a name="132622102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132622102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132622102">(Aug 23 2018 at 07:08)</a>:</h4>
<p>we do need a way to know whether <code>rustfix</code> needs to add <code>::</code> or not, to refer to crates, so it's actually a must. and we have to fix <code>rustfmt</code> to not strip leading <code>::</code> if <code>uniform_paths</code> is enabled</p>
<p>we could also add canaries for <code>::foo</code> and <code>self::foo</code> and basically check whether an ambiguity error <em>would</em> be emitted and just suggest removing the <code>::</code> / <code>self::</code> if they don't trigger, so you can just run <code>rustfix</code>!</p>



<a name="132622238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132622238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132622238">(Aug 23 2018 at 07:13)</a>:</h4>
<p>hang on, how did I not notice this before: because of how the canaries work now, we gather N of them, plus an implicit <code>external_prelude</code> one and then require that only one succeeds. if we make the <code>external_prelude</code> one an explicit <code>::name</code> canary, then we can actually have <code>uniform_paths</code> on Rust2015, modulo ambiguities from macro expansion shenanigans (but the canaries <em>would</em> catch those!).</p>
<p>We just have to be careful to not do explicit <code>::name</code> in Rust2018 because that would forcefully load an <code>extern crate</code>.</p>
<p>Also, maybe only <code>use ::foo;</code> should do the "forceful" thing, and <code>::foo</code> paths elsewhere. I know it's not consistent but it's closer to requiring <code>--extern foo</code> and having to put that in <code>Cargo.toml</code>. <em>although</em>, we <em>could just</em> implement the <code>Cargo.toml</code> thing <em>now</em>. does <code>rustfix</code> know how to edit <code>Cargo.toml</code>? Because that <em>would be</em> grand :D</p>



<a name="132622404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uniform-paths/near/132622404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uniform-paths.html#132622404">(Aug 23 2018 at 07:18)</a>:</h4>
<p>awww just saw <a href="https://github.com/rust-lang/rust/issues/53130#issuecomment-415217754" target="_blank" title="https://github.com/rust-lang/rust/issues/53130#issuecomment-415217754">https://github.com/rust-lang/rust/issues/53130#issuecomment-415217754</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>